<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->order_status;
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	if(!empty($_RQ['goodstitle'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['goodstitle']).'%';
		$goodsids=pdo_getall('jy_xunichong_goods',$params2,'id','id');
		if($goodsids){
			$goodsids=array_keys($goodsids);
			$params['goodsid']=$goodsids;
		}
		$return['params']['goodstitle']=$_RQ['goodstitle'];
	}
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	if(isset($_RQ['ordersn'])){
		$params['ordersn']=$_RQ['ordersn'];
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_xunichong_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['goodstitle']=pdo_getcolumn('jy_xunichong_goods',array('id'=>$item['goodsid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'modal','action'=>'/order/detail/','title'=>'订单详情_Detail'),
			array('type'=>'modal','action'=>'/order/hexiao/','title'=>'核销','show'=>array('status'=>1)),			
		)
		),
		'search'=>array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string','width'=>15),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string','width'=>15),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	$item=$this->pdo_get('order',array('id'=>$id));	
	$item['member']=cfc('core')->member_show($item['mid']);
	$item['goodstitle']=pdo_getcolumn('jy_xunichong_goods',array('id'=>$item['goodsid']),'title');
	$htmls=array(
		'type'=>'look',
		'desc'=>'订单详情',
	);
	$htmls['look']=array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='hexiao'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$hexiao=intval($post['hexiao']);
		$id=intval($post['id']);
		if($hexiao){
			$this->model('model')->sendgoods($post);
		}
		exi('操作成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$item=$this->pdo_get('order',array('id'=>$id));	
	$item['member']=cfc('core')->member_show($item['mid']);
	$item['goodstitle']=pdo_getcolumn('jy_xunichong_goods',array('id'=>$item['goodsid']),'title');
	$htmls=array(
		'type'=>'edit',
		'desc'=>'订单核销',
	);
	$htmls['edit']=array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'oldprice','title'=>'面值','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
			array('name'=>'hexiao','title'=>'核销状态','type'=>'radio','options'=>'hexiao_status'),
	);
	$return['hexiao_status']=$this->hexiao_status;
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_xunichong_order',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_xunichong_order',array('id'=>$id));
			}
		}
	}
	exi('删除成功！','','list');
}